#include <cstdio>
#include <vector>
#include <algorithm>
//#include <iostream>
//#include <iterator>
using namespace std;

#define MAX_LENGTH 100

template< typename T, typename _InIt, typename _Fn1 >
void LIS( _InIt begin, _InIt end, _Fn1 f )
{
	struct LISN
	{
		int prev;
		int length;

		LISN()
		{
			prev = -1;
			length = 1;
		}
	};

	LISN nodes[ MAX_LENGTH ];

	int maxpos = -1;

	for( int i = 1; i < end - begin; i++ )
	{
		int pos = -1;
		for( int k = 0; k < i; k++ )
		{
			if( *(begin + k) < *(begin + i) )
			{
				if( pos == -1 || nodes[pos].length < nodes[k].length )
				{
					pos = k;
				}
			}
		}

		if( pos != -1 )
		{
			nodes[i].prev = pos;
			nodes[i].length = nodes[pos].length + 1;
		}

		if( maxpos == -1 || nodes[maxpos].length < nodes[i].length )
		{
			maxpos = i;
		}
	}

	T* rlist[ MAX_LENGTH ] = { NULL };

	int j = 0;
	for( int i = maxpos; i != -1; i = nodes[i].prev )
	{
		rlist[j++] = &( *(begin + i) );
	}

	f( rlist, j );
}

struct BOX
{
	int lines[10];
	int line_count;
	int line_length_sum;
	int order;

	void assign( int line_count, int order )
	{
		std::sort( lines, lines + line_count );
		this->line_count = line_count;
		this->line_length_sum = 0;
		for( int i = 0; i < this->line_count; i++ )
		{
			this->line_length_sum += lines[i];
		}
		this->order = order;
	}
	
	bool operator < ( const BOX& dbox )
	{
		for( int i = this->line_count - 1; i >= 0; i-- )
		{
			if( lines[i] >= dbox.lines[i] )
			{
				return false;
			}
		}
		return true;
	}
};

bool first = true;
void print_ans( BOX** pbox, int count )
{
	if( first )
	{
		first = false;
	}
	else
	{
		printf( "\n" );
	}
	printf( "%d", count );
	if( count > 0 )
	{
		printf( "\n" );
		for( int i = count - 1; i >= 0; i-- )
		{
			printf( "%d", pbox[i]->order );
			if( i != 0 )
			{
				printf( " " );
			}
		}
	}
}

bool compare_box_length_sum( const BOX& b1, const BOX& b2 )
{
	return b1.line_length_sum < b2.line_length_sum;
}

int main( int argc, char* argv[] )
{
	while( 1 )
	{
		int box_count = 0;
		int dimensions = 0;

		if( scanf( "%d %d", &box_count, &dimensions ) != 2 )
		{
			break;
		}

		vector<BOX> boxs( box_count );
		for( int i = 0; i < box_count; i++ )
		{
			BOX& box = boxs[i];
			for( int j = 0; j < dimensions; j++ )
			{
				scanf( "%d", &(box.lines[j]) );
			}
			box.assign( dimensions, i + 1 );
		}

		std::sort( boxs.begin(), boxs.end(), compare_box_length_sum );

		LIS<BOX>( boxs.begin(), boxs.end(), print_ans );
	}

	return 0;
}
